<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h2 class="counter"></h2>
  <button class="increament">+1</button>
  <button class="decrement">-1</button>

  <script>
    // 获取所有的原生组件
    const counterEl = document.querySelector(".counter");
    const increamentEll = document.querySelector(".increament");
    const decrementEl = document.querySelector(".decrement");

    // 定义变量
    let counter = 100;
    counterEl.innerHTML = counter;

    // 监听按钮的点击
    increamentEll.addEventListener("click", () => {
      counter = counter + 1;
      counterEl.innerHTML = counter;
    });
    decrementEl.addEventListener("click", () => {
      counter = counter - 1;
      counterEl.innerHTML = counter;
    });

  </script>

</body>

</html>